package flc.ast.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.nettool.lib.MtrInfo;

import org.jetbrains.annotations.NotNull;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;


public class MtrInfoAdapter extends StkProviderMultiAdapter<MtrInfo> {

    public MtrInfoAdapter() {
        super(1);
        addItemProvider(new MyItemProvider());
    }

    private class MyItemProvider extends BaseItemProvider<MtrInfo> {

        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_mtr;
        }

        @Override
        public void convert(@NotNull BaseViewHolder holder, MtrInfo info) {
            int pos = holder.getAdapterPosition() + 1;
            holder.setText(R.id.tvNumber, "" + pos);
            holder.setText(R.id.tvIp, info.ip);
            holder.setText(R.id.tvLoss, "loss " + info.getLossPercent() + "%");
            String time = String.format("%.2f ms", info.delayTime);
            holder.setText(R.id.tvTime, time);

            ImageView ivStatus = holder.getView(R.id.ivStatus);
            ivStatus.setSelected(true);
        }
    }

}
